var DAO = require('./DAO')
var collectionDAO = {
    //查询收藏表的信息
    getcollectionList: function (userId, callback) {
        DAO('select collectionId,productName,productPic,product.productId,price from collection,product where product.productId=collection.productId and userId=?', [userId], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    getProductId:function(productId,callback){
        DAO('select * from collection where productId=?',[productId],function(err,results){
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    //新增收藏表的数据
    addProduct: function (collection, callback) {
        DAO('insert into collection(productId,userId) value(?,?)', [collection.productId, collection.userId], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    },
    //删除收藏表的数据
    delProduct: function (collectionId, callback) {
        DAO('delete from collection where collectionId = ?', [collectionId], function (err, results) {
            if (err) {
                callback(err, null)
            } else {
                callback(null, results)
            }
        })
    }
}
module.exports = collectionDAO
